/* eslint-disable react/prop-types */
//  import {createStore} from "redux" 已被代替
 import {configureStore} from "@reduxjs/toolkit"
 import ReactDOM from 'react-dom';
 
 function Reducer(state=0, action) {
     const {type} = action;
     if(type==='increment'){
        return state +21;
     } else if(type==='decrement'){
        return state-1;
     }
     else {
        return state;
     }
 }
 //基于reducer创建store
 let stateBaseValue = 101;
 const store = configureStore(Reducer,stateBaseValue);
 //获取 store的状态
 console.log(store.getState())


//更新store的状态
setTimeout(() => {
    store.dispatch({type:'increment',  

});
}, 1000);

//订阅store 中 state的变化
store.subscribe(()=> {
    console.log(store.getState())
})


 const Counter = (props) =>{
    return (
        <div>
            <h1>{props.value}</h1>
            <button>add</button>
            <button>reduce</button>
        </div>
    )
 }
//createRoot 代替 render
 ReactDOM.createRoot(<Counter value = {store.getState()}/>, document.getElementById("root"))